package com.blog.admin.controller;

import com.alibaba.fastjson.JSONObject;
import com.blog.admin.entity.SysUser;
import com.blog.admin.service.SysUserService;
import com.blog.admin.vo.PageVo;
import com.blog.admin.vo.WebResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("sysuser")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 组合查询+分页查询所有用户信息(sys_user表)
     */
    @PostMapping("findUserDetail")
    public WebResult<PageVo<SysUser>> findUserDetail(@RequestBody JSONObject param) {
        return WebResult.<PageVo<SysUser>>builder()
                .code(200)
                .message(WebResult.REQUEST_STATUS_SUCCESS)
                .data(sysUserService.findUserDetail(param))
                .build();
    }

    /**
     * 删除用户接口
     * @param id
     */
    @GetMapping("deleteUserById")
    public WebResult<String> deleteUserById(@RequestParam("id") long id) {
        sysUserService.deleteUserById(id);
        return WebResult.<String>builder()
                .code(200)
                .message(WebResult.REQUEST_STATUS_SUCCESS)
                .build();
    }


    /**
     * 更新用户接口
     */
    @PostMapping("updateUserById")
    public void updateUserById(@RequestBody JSONObject param) {
        sysUserService.updateUserById(param);
    }

}
